//
//  UIViewAnimateDemo.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/4/27.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit

class UIViewAnimateDemo: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        
        let viewA = UIView(frame: CGRect(x: 20, y: 40*2, width: 40, height: 40))
        viewA.backgroundColor = UIColor.blue
        
        let viewB = UIView(frame: CGRect(x: 20, y: 40*3, width: 40, height: 40))
        viewB.backgroundColor = UIColor.yellow
        
        let viewC = UIView(frame: CGRect(x: 20, y: 40*4, width: 40, height: 40))
        viewC.backgroundColor = UIColor.darkGray
        
        let viewD = UIView(frame: CGRect(x: 20, y: 40*5, width: 40, height: 40))
        viewD.backgroundColor = UIColor.black
        
        self.view.addSubview(viewA)
        self.view.addSubview(viewB)
        self.view.addSubview(viewC)
        self.view.addSubview(viewD)
        
        
        UIView.animate(withDuration: 2) {
            //水平移动
            viewA.center.x = self.view.bounds.width - viewA.center.x
            //旋转
            viewA.transform = viewA.transform.rotated(by: 360)
        }
        UIView.animate(withDuration: 2, delay: 0, options: [.repeat,.curveLinear], animations: {
            viewB.center.x = self.view.bounds.width - viewB.center.x
            
        }) { (fals) in
            print(fals)
        }
        
        UIView.animate(withDuration: 2, delay: 0, options: [.repeat,.autoreverse], animations: {
            viewC.center.x = self.view.bounds.width - viewC.center.x
            //设置透明度
            viewC.alpha = 0.2
            //按比例缩放
            viewC.transform = viewC.transform.scaledBy(x: 2, y: 1)
        }) { (fals) in
            
        }
        
        UIView.animate(withDuration: 15, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 1, options: [], animations: {
            viewD.center.x = self.view.bounds.width - viewD.center.x
        }) { (fals) in
            
        }
    
        
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
